package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectsService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("nursing_project")
@Api(tags="护工项目相关接口")
public class NursingProjectsController extends BaseController {

    @Autowired
    private NursingProjectsService nursingProjectsService;


    @GetMapping
    @ApiOperation("护工项目分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> queryPage(@ApiParam(value = "护工项目名称") String name,
                                                                    @ApiParam(value = "当前页码")@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(value = "每页显示条数")@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                    @ApiParam(value = "状态") Integer status){
        PageResponse<NursingProjectVo> response = nursingProjectsService.queryPage(name,pageNum,pageSize,status);
        return success(response);
    }


    @PostMapping
    @ApiOperation("新增护理项目")
    public  ResponseResult add(@ApiParam(value = "护理项目数据传输对象")@RequestBody NursingProjectDto nursingProjectDto){
        logger.info("新增护理项目，参数为"+nursingProjectDto);
        nursingProjectsService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理")
    public ResponseResult findById(@ApiParam("护理项目id")@PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectsService.findById(id);
        return success(nursingProjectVo);
    }


    @PutMapping
    @ApiOperation("编辑")
    public  ResponseResult update(@ApiParam("编辑参数")@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectsService.update(nursingProjectDto);
        return success();
    }

}
